package com.jarvis.pzz.modules.main.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jarvis.pzz.R;
import com.jarvis.pzz.models.SearchTypeModel;
import com.jarvis.pzz.util.ViewHolderUtil;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by jarvis.liu on 9/12/2016.
 */
public class ZpAdapter extends BaseAdapter {
    private List<SearchTypeModel> list;
    private Context context;

    public ZpAdapter(List<SearchTypeModel> list, Context context) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_main, null);
            holder.img = (ImageView) convertView.findViewById(R.id.img);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SearchTypeModel mainGridModel = list.get(position);
        if (TextUtils.isEmpty(mainGridModel.getImg_url())) {
            holder.img.setVisibility(View.GONE);
        } else {
            holder.img.setVisibility(View.VISIBLE);
            //Glide.with(context).load(mainGridModel.getImg_url()).skipMemoryCache(true).into(holder.img);
            Picasso.with(context).load(mainGridModel.getImg_url()).into(holder.img);
        }
        holder.tv_name.setText(mainGridModel.getDisplayValue());
//        if (position == 11) {
//            holder.tv_name.setTextColor(context.getResources().getColor(R.color.purple));
//        } else {
//            holder.tv_name.setTextColor(context.getResources().getColor(R.color.grey));
//        }
        holder.tv_name.setTextColor(context.getResources().getColor(R.color.grey));
        return convertView;
    }

}

class ViewHolder {
    public ImageView img;
    public TextView tv_name;
}

